package luke.core.utils;

import com.formdev.flatlaf.FlatDarkLaf;
import javax.swing.*;
import java.awt.*;

/**
 * 主题管理器类，用于设置和管理应用程序的主题
 */
public class ThemeManager {
    
    /**
     * 设置暗灰色主题
     */
    public static void setupDarkGrayTheme() {
        try {
            // 设置FlatLaf暗色主题
            FlatDarkLaf.setup();
            
            // 自定义圆角设置
            UIManager.put("Button.arc", 12);
            UIManager.put("Component.arc", 12);
            UIManager.put("TextComponent.arc", 8);
            
            // 自定义暗灰色主题颜色
            UIManager.put("Panel.background", new Color(50, 50, 50));
            UIManager.put("ToolBar.background", new Color(60, 60, 60));
            UIManager.put("MenuBar.background", new Color(60, 60, 60));
            UIManager.put("Menu.background", new Color(60, 60, 60));
            UIManager.put("MenuItem.background", new Color(60, 60, 60));
            UIManager.put("TabbedPane.background", new Color(50, 50, 50));
            UIManager.put("TabbedPane.contentAreaColor", new Color(50, 50, 50));
            UIManager.put("TabbedPane.selected", new Color(70, 70, 70));
            UIManager.put("ScrollBar.track", new Color(60, 60, 60));
            UIManager.put("ScrollBar.thumb", new Color(100, 100, 100));
            UIManager.put("ScrollBar.thumbDarkShadow", new Color(80, 80, 80));
            UIManager.put("ScrollBar.thumbHighlight", new Color(120, 120, 120));
            
            // 文本颜色设置
            UIManager.put("Label.foreground", new Color(220, 220, 220));
            UIManager.put("Button.foreground", new Color(220, 220, 220));
            UIManager.put("TextField.foreground", new Color(220, 220, 220));
            UIManager.put("TextArea.foreground", new Color(220, 220, 220));
            UIManager.put("ComboBox.foreground", new Color(220, 220, 220));
            UIManager.put("List.foreground", new Color(220, 220, 220));
            UIManager.put("Tree.foreground", new Color(220, 220, 220));
            UIManager.put("Table.foreground", new Color(220, 220, 220));
            
            // 选中项背景色
            UIManager.put("List.selectionBackground", new Color(80, 80, 80));
            UIManager.put("Tree.selectionBackground", new Color(80, 80, 80));
            UIManager.put("Table.selectionBackground", new Color(80, 80, 80));
            UIManager.put("TextField.selectionBackground", new Color(80, 80, 80));
            
            // 边框颜色
            UIManager.put("Component.focusWidth", 1);
            UIManager.put("Component.innerFocusWidth", 1);
            UIManager.put("Button.focusedBackground", new Color(70, 70, 70));
            
            // 按钮样式
            UIManager.put("Button.background", new Color(70, 70, 70));
            UIManager.put("Button.default.background", new Color(90, 90, 90));
            
            // 进度条颜色
            UIManager.put("ProgressBar.background", new Color(60, 60, 60));
            UIManager.put("ProgressBar.foreground", new Color(100, 100, 100));
            
            // 滑块颜色
            UIManager.put("Slider.trackColor", new Color(60, 60, 60));
            UIManager.put("Slider.thumbColor", new Color(120, 120, 120));
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    /**
     * 应用主题设置并更新所有组件
     */
    public static void applyTheme() {
        // 更新所有打开的窗口
        for (Window window : Window.getWindows()) {
            SwingUtilities.updateComponentTreeUI(window);
        }
    }
}